<template>
  <div class="app-container org">
    <el-card style="width: 100%">
      <p class="pinformation">搜索条件</p>
      <el-form :model="queryParams" ref="queryRef" label-width="80px">
        <el-row>
          <el-col :span="3">
            <el-form-item label="方法编号：" prop="methodCode">
              <el-input v-model="queryParams.methodCode" placeholder="请输入方法编号" maxlength="100" clearable
                @keyup.enter="handleQuery" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="方法名称：" prop="methodName">
              <el-input v-model="queryParams.methodName" maxlength="100" placeholder="请输入方法名称" clearable
                @keyup.enter="handleQuery" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="检测时间：">
              <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
                start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="方案编号：" prop="projectCode">
              <el-input v-model="queryParams.projectCode" placeholder="请输入方案编号" maxlength="100" clearable
                @keyup.enter="handleQuery" />
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item label="状态：" prop="userStatus">
              <el-select v-model="queryParams.userStatus">
                <el-option label="待审核" :value="0"></el-option>
                <el-option label="已审核" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-row justify="end">
              <el-button type="success" @click="handleQuery">搜索</el-button>
              <el-button class="business resetBtn" @click="resetQuery">重置</el-button>
            </el-row>
          </el-col>
        </el-row>
      </el-form>
      <el-row>
        <p class="pinformation">原始记录表列表</p>
        <p class="totalStyle">共 {{ total }} 条数据</p>
      </el-row>
      <el-table
        ref="mainTableRef"
        v-loading="loading"
        :show-overflow-tooltip="true"
        class="business"
        :data="ysjlbList"
      >
      <el-table-column
          label="方案编号"
          align="center"
          prop="projectCode"
          width="130"
        />
        <el-table-column
          label="方案名称"
          align="center"
          prop="projectName"
        />
        <el-table-column label="方法名称" align="center">
            <template #default="scope">
              {{ scope.row.methodCode }} <span v-html="proxy.getSupAndSub(scope.row.methodName)"></span>
            </template>
        </el-table-column>
        <el-table-column label="检测时间" align="center" width="200">
          <template #default="scope">
            <span v-if="scope.row.startDate == scope.row.endDate">
              {{ scope.row.startDate }}
            </span>
            <span v-else>
              {{ scope.row.startDate }} 至 {{ scope.row.endDate }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="填报人"
          align="center"
          prop="createUserName"
          width="120"
        />
        <el-table-column
          label="样品数量"
          align="center"
          prop="sampleCount"
          width="90"
        />
        <el-table-column
          label="接收时间"
          align="center"
          prop="userCreateTime"
          width="160"
        />
        <el-table-column
          label="状态"
          align="center"
          prop="stepName"
          width="120"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="150"
        >
          <template #default="scope">
            <el-button link type="success" @click="handleCheck(scope.row)" v-if="scope.row.userStatus == 0">审核</el-button>
            <el-button link type="success" @click="handleCheck(scope.row)" v-else>查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <checkDialog ref="checkRef" @close="close"></checkDialog>
  </div>
</template>

<script setup name="LabTaskApprove">
import checkDialog from "./checkDialog.vue";
import { listLabTask } from "@/api/lab/labTask";

const { proxy } = getCurrentInstance();
const queryParams = ref({ pageNum: 1, pageSize: 10, userStepId: 2, userStatus: 0 });
const dateRange = ref([]);
const dateRange1 = ref([]);
const ysjlbList = ref([]);
const loading = ref(false);
const total = ref(0);
const checkRef = ref(null)

function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
function resetQuery() {
  dateRange.value = [];
  dateRange1.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}
function getList() {
  listLabTask(proxy.addDateRange(queryParams.value, dateRange.value)).then((res) => {
    ysjlbList.value = res.rows;
    total.value = res.total;
  });
}
getList();

function handleCheck(row) {
  checkRef.value.handleCheck(row.myId)
}


watch(
  () => total.value,
  () => {
    if (total.value) {
      heightParams.value = [{ tableName: "main", bottomHeight: 73 }];
    } else {
      heightParams.value = [{ tableName: "main", bottomHeight: 21 }];
    }
    getTableHeight();
  }
);
// 自适应样式
const heightParams = ref([{ tableName: "main", bottomHeight: 21 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}
onMounted(() => {
  nextTick(() => {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  })
})
onUpdated(() => {
  nextTick(function () {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});

function close(val) {
  if (val) {
    getList()
  }
}
</script>
